﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace CarShopManagerDAL
{
    public class CarInfoDAL
    {
        /// <summary>
        /// 车辆预定列表
        /// </summary>
        /// <param name="carName">车辆名称</param>
        /// <param name="carType">车辆类型</param>
        /// <returns></returns>
        public static DataTable GetCarOrderList(string carName,int carType)
        {
            string sqlstr = "select a.*,b.Name ClientName from CarInfo a left  join CarClient b on a.Id=b.CarId where 1=1 ";
            if (carName != "")
            {
                sqlstr += " and a.Name='" + carName + "'";
            }
            if (carType != 0)
            {
                sqlstr += " and CarType="+carType;
            }
            return DBHelper.GetTable(sqlstr);
        }
        /// <summary>
        /// 根据车辆编号查询车辆信息
        /// </summary>
        /// <param name="id">车辆编号</param>
        /// <returns></returns>
        public static DataTable GetCarInfoById(int id)
        {
            string sqlstr = "select * from CarInfo where Id="+id;
            return DBHelper.GetTable(sqlstr);
        }
        /// <summary>
        /// 修改车辆状态和销售日期
        /// </summary>
        /// <param name="id">车辆编号</param>
        /// <returns></returns>
        public static int UpdateCarInfo(int id)
        {
            string sqlstr = "update CarInfo set CarState=1,SellingDate='"+DateTime.Now+"' where Id=" + id;
            return DBHelper.ExcuteNonQuery(sqlstr);
        }
    }
}
